using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System;
using System.Diagnostics;
using FlickrShots.Framework;

namespace FlickrShots.GUI.controls
{
	public class UserInformationControl : UserControl
	{
        private PictureBox buddyIcon;
        private LinkLabel userName;
        private Label userStatus;

		private Container components = null;

		public UserInformationControl()
		{
			InitializeComponent();
		    InitializeDisplay();
		}

	    protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.buddyIcon = new System.Windows.Forms.PictureBox();
            this.userName = new System.Windows.Forms.LinkLabel();
            this.userStatus = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.buddyIcon)).BeginInit();
            this.SuspendLayout();
            // 
            // buddyIcon
            // 
            this.buddyIcon.Location = new System.Drawing.Point(77, 3);
            this.buddyIcon.Name = "buddyIcon";
            this.buddyIcon.Size = new System.Drawing.Size(66, 50);
            this.buddyIcon.TabIndex = 0;
            this.buddyIcon.TabStop = false;
            // 
            // userName
            // 
            this.userName.AutoSize = true;
            this.userName.Location = new System.Drawing.Point(3, 16);
            this.userName.Name = "userName";
            this.userName.Size = new System.Drawing.Size(69, 13);
            this.userName.TabIndex = 4;
            this.userName.TabStop = true;
            this.userName.Text = "<UserName>";
            // 
            // userStatus
            // 
            this.userStatus.AutoSize = true;
            this.userStatus.Location = new System.Drawing.Point(3, 3);
            this.userStatus.Name = "userStatus";
            this.userStatus.Size = new System.Drawing.Size(68, 13);
            this.userStatus.TabIndex = 3;
            this.userStatus.Text = "Logged in as";
            // 
            // UserInformationControl
            // 
            this.Controls.Add(this.buddyIcon);
            this.Controls.Add(this.userName);
            this.Controls.Add(this.userStatus);
            this.Name = "UserInformationControl";
            this.Size = new System.Drawing.Size(151, 56);
            ((System.ComponentModel.ISupportInitialize)(this.buddyIcon)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
		#endregion

	    private void InitializeDisplay()
	    {
	        Visible = false;
	    }
	    
	    public void UpdateUserInformation(object source, EventArgs args)
	    {
	        Visible = true;
            User user = User.NullUser;
	        userName.Text = user.Name;
            userName.Links.Clear();
            userName.Links.Add(0, user.Link.Length, user.Link);
            userName.LinkClicked += new LinkLabelLinkClickedEventHandler(OpenFlickrUserHomePage);

            buddyIcon.Image = user.BuddyIcon;
	    }

        void OpenFlickrUserHomePage(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(e.Link.LinkData.ToString());
        }
	}
}